package com.health.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 返回值，由前后端协定
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Result<T> {

    /**
     * 成功返回true，失败返回false
     */
    private boolean flag;

    private String message;

    private T data;

    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.flag = true;
        result.message = "操作成功";
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<>();
        result.data = object;
        result.flag = true;
        result.message = "操作成功";
        return result;
    }


    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.message = msg;
        result.flag = false;
        return result;
    }

}
